version 18
set more off
clear all
set maxvar 20000
quietly log
local logon = r(status)
if "`logon'" == "on" { 
	log close 
	}
log using bsgs2026jleo-analysis, text replace

/*		************************************************************************	*/
/*     	File Name:		bsgs2026jleo-analysis.do									*/
/*     	Date:   		February 13, 2026											*/
/*      Author: 		Frederick J. Boehmke										*/
/*      Purpose:		Replication file for Boehmke, Shipan, Goehring, and 		*/
/*						Saunders' JLEO article analyzing the effect of local and 	*/
/*						state legislator ideology on nursing home inspections.		*/
/*						This file estimates the models and makes the tables.		*/
/*      Input File:		bsgs2026jleo.dta											*/
/*      Output File:	bsgs2026jleo-analysis.log									*/
/*						tables/bsgs2026jleo-tableXX.txt								*/
/*						figures/bsgs2026jleo-figureXX.png							*/
/*						bsgs2026jleo-estimates-tableXX-modelYY.ster					*/
/* 		Packages:		estout.pkg, parmest.pkg										*/ 
/*		************************************************************************	*/

/*  Run the two lines below lines to install the needed packages.
net install estout, from(http://fmwww.bc.edu/RePEc/bocode/e)
ssc install parmest
*/

		/* Create the required folders if they don't exist already. */
		
capture mkdir figures
capture mkdir tables

		/* Open the data. */

use bsgs2026jleo, clear


	/****************************************************************/
	/* Remove cases with bedsocc outliers. It's probably possible   */  
	/* to have values greater than 1, but at some point it suggests */
	/* a potential error in the beds or occupancy variables.        */
	/* Alternative models with different cutoff are included below. */
	/****************************************************************/
	
	
egen provid=group(provnum)

xtset provid surv_num

generat numbeds_diff = numbeds - l.numbeds
generat bedsocc_diff = bedsocc - l.bedsocc

tab bedsocc if bedsocc > 1
tab bedsocc if bedsocc > 1, missing

drop if bedsocc > 1.5 & !missing(bedsocc)


	/**************************************/
	/* Table 1: Basic summary statistics. */
	/**************************************/

	
xi, noomit: estpost sum def_all loc_house_avg loc_senate_inmaj loc_house_inmaj loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care hospital own_nonp own_govt i.resfam 

		/* Output table. See above to install estout package if needed. */
	
	esttab using tables/bsgs2026jleo-table-01.txt, modelwidth(5 5 5 5 8)  ///
	cell((mean(fmt(%9.2f) label(Mean)) sd(fmt(%9.2f) label(SD)) min(fmt(%9.2f) label(Min.)) ///
		max(fmt(%9.2f) label(Max.)) count(fmt(%9.0fc) label(N)))) ///
	label nomtitle nonumber replace noobs varwidth(50) ///
	coeflabels(_Iresfam_1 "Resident and Family Council" _Iresfam_2 "Resident Council Only"  ///
	  _Iresfam_3 "Family Council Only" _Iresfam_4 "No Resident or Family Council") 

		/* Table of deficiencies by state. */
	
table state, stat(mean def_all) stat(mean def_sev) missing

		/* Correlation in chamber ideology variables in our data. */

correlate hou_chamber sen_chamber

		/* Correlation in chamber ideology variables at the state level. Preserve the */
		/* data, drop to one observation per state to correlate, then restore the data. */

preserve

keep state year hou_chamber sen_chamber

duplicates drop

correlate hou_chamber sen_chamber

restore


	/************/
	/* Table 2. */
	/************/

		/* Model 1: local representation measured with average ideology. */
		
menbreg def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store local_avg_re

	/* Model 2: local and state representation using lower chamber. */
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store locst_avg_re
	
		/* Save these estimates to a file to use in the interpretation later. */
	
	estimates save bsgs2026jleo-estimates-table02-model02, replace
		
		/* Model 3: also add interaction for majority status.    */

menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj ///
	1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store inmaj_avg_re
	
		/* Save these estimates to a file to use in the interpretation later. */
	
	estimates save bsgs2026jleo-estimates-table02-model03, replace
	
		/* Effect of ideology for representatives with chamber majority status. */
	
lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					
lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg					
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
		/* Shorten labels for the tables. */ 
	
label variable loc_house_avg 		"Lower Representative Ideology"
label variable loc_senate_avg		"Upper Representative Ideology" 
label variable loc_house_avg_dist 	"Lower Representative Ideology"
label variable loc_senate_avg_dist 	"Upper Representative Ideology" 
label variable hou_chamber 			"Lower Chamber Ideology"
label variable loc_house_inmaj 		"Lower Rep. in Majority"
label variable loc_senate_inmaj 	"Upper Rep. in Majority"
label variable legp_squire_ipol 	"Legislative Professionalism"
	
		/* Output the table as a text file. */
	
estout local_avg_re locst_avg_re inmaj_avg_re using tables/bsgs2026jleo-table-02.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N, fmt(%9.0gc)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.1. */
	/****************/
	
		/* Repeat previous table with exponentiated coefficients. */

estout local_avg_re locst_avg_re inmaj_avg_re using tables/bsgs2026jleo-table-SI01.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N, fmt(%9.0gc)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	

	/****************/
	/* Table SI.2a. */
	/****************/
	
		/* Local and state representation with legislative capacity measure. */
		/* This is based on the model 2 from table 2 and adds the Bowen */
		/* and Greene measure with extrapolation. */
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	legp_bg_cs1_ipol c.legp_bg_cs1_ipol#c.hou_chamber c.legp_bg_cs1_ipol#c.loc_house_avg c.legp_bg_cs1_ipol#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:

	estimates store legp_bg_avg_re
	
		/* Save these estimates to a file to use in the interpretation later. */
	
	estimates save bsgs2026jleo-estimates-tableSI2a, replace
	
		/* Effect of ideology by professionalism. */
	
forvalues legp = -2/9 {	
	
	lincom hou_chamber + c.hou_chamber#c.legp_bg_cs1_ipol*`legp'					

	}
	
forvalues legp = -2/9 {	
	
	lincom loc_house_avg + c.loc_house_avg#c.legp_bg_cs1_ipol*`legp'					

	}
	
forvalues legp = -2/9 {	
	
	lincom loc_senate_avg + c.loc_senate_avg#c.legp_bg_cs1_ipol*`legp'					

	}
	
		/* Alternate version with Squire measure with interpolation and extrapolation. */
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	legp_squire_ipol c.legp_squire_ipol#c.hou_chamber c.legp_squire_ipol#c.loc_house_avg c.legp_squire_ipol#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:

	estimates store legp_sq_avg_re
	
		/* Effect of ideology by professionalism. */
	
forvalues legp = 0(0.1)0.7 {	
	
	lincom hou_chamber + c.hou_chamber#c.legp_squire_ipol*`legp'					

	}
	
forvalues legp = 0(0.1)0.7 {	
	
	lincom loc_house_avg + c.loc_house_avg#c.legp_squire_ipol*`legp'					

	}
	
forvalues legp = 0(0.1)0.7 {	
	
	lincom loc_senate_avg + c.loc_senate_avg#c.legp_squire_ipol*`legp'					

	}
	
		/* Table in the SI just includes the Bowen and Greene version. */
	
estout legp_bg_avg_re using tables/bsgs2026jleo-table-SI2a.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep ///
	  legp_bg_ipol c.legp_bg_ipol*c.loc_house_avg c.legp_bg_ipol*c.loc_senate_avg ///
	  c.legp_bg_ipol*c.hou_chamber) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N, fmt(%9.0gc)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(c.legp_bg_ipol#c.loc_house_avg "Lower Rep. Ideology * Leg. Prof." ///
	  c.legp_bg_ipol#c.loc_senate_avg "Upper Rep. Ideology *  Leg. Prof." ///
	  c.legp_bg_ipol#c.hou_chamber "Lower Chamber Ideology *  Leg. Prof." ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.2b. */
	/****************/

		/* Repeat previous table with exponentiated coefficients. */

estout legp_bg_avg_re using tables/bsgs2026jleo-table-SI2b.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep ///
	  legp_bg_ipol c.legp_bg_ipol*c.loc_house_avg c.legp_bg_ipol*c.loc_senate_avg ///
	  c.legp_bg_ipol*c.hou_chamber) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N, fmt(%9.0gc)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(exp(@) exp(@)) ///
	label varlabel(c.legp_bg_ipol#c.loc_house_avg "Lower Rep. Ideology * Leg. Prof." ///
	  c.legp_bg_ipol#c.loc_senate_avg "Upper Rep. Ideology *  Leg. Prof." ///
	  c.legp_bg_ipol#c.hou_chamber "Lower Chamber Ideology *  Leg. Prof." ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/***************/
	/* Table SI.4. */
	/***************/

		/* Main models as zero-inflated Negative Binomial. */
		/* First: how many cases are zeros in the base estimation sample? */
		
estimates esample : def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt resfam year stateno, replace
		
tab def_all if e(sample) == 1

		/* Preserve the data to drop to a facility-level data set to */
		/* calculate how many facilities always have zeros then restore. */
		
preserve

egen all_zero = sum(def_all), by(provid)

keep provid all_zero 
keep if e(sample) == 1

duplicates drop

tab all_zero 

restore
		
		/* Estimate the zero-inflated models. The formulas in the Stata manual suggest  */
		/* that the inflate equation models the probability of an always-zero observation. */
	
zinb def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno, ///
	inflate(numbeds bedsocc rnhrspc med_caid med_care ///
	  hospital own_nonp own_govt ib4.resfam) vce(robust)
	
	estimates store m1_zinb
	
zinb def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno, ///
	inflate(numbeds bedsocc rnhrspc med_caid med_care ///
	  hospital own_nonp own_govt ib4.resfam) vce(robust)
	
	estimates store m2_zinb
	
zinb def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno, ///
	inflate(numbeds bedsocc rnhrspc med_caid med_care ///
	  hospital own_nonp own_govt ib4.resfam) vce(robust)
	  
	estimates store m3_zinb
	
		/* Effect of ideology for representatives with chamber majority status. */
		/* Add these to tables to facilitate interpretation in the SI. */
	
	lincom [def_all]_b[loc_house_avg] + [def_all]_b[1.loc_house_inmaj#c.loc_house_avg]

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom [def_all]_b[loc_senate_avg] + [def_all]_b[1.loc_senate_inmaj#c.loc_senate_avg]

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
		
estout m1_zinb m2_zinb m3_zinb using tables/bsgs2026jleo-table-SI04.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	

	/***************/
	/* Table SI.5. */
	/***************/

		/* Robustness: estimate severe deficiencies only. */
	
menbreg def_sev loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store m1_severe
	
menbreg def_sev loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store m2_severe
	
menbreg def_sev loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store m3_severe
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
estout m1_severe m2_severe m3_severe using tables/bsgs2026jleo-table-SI05.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/***************/
	/* Table SI.6. */
	/***************/

		/* Robustness: estimate nonsevere deficiencies only. */	
	
menbreg def_nonsev loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store m1_nonsev
	
menbreg def_nonsev loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store m2_nonsev
	
menbreg def_nonsev loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
	estimates store m3_nonsev
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
estout m1_nonsev m2_nonsev m3_nonsev using tables/bsgs2026jleo-table-SI06.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)

	
	/***************/
	/* Table SI.7. */
	/***************/

		/* Robustness: Add in RUCA code for urban-rule effects. */

menbreg def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam ib4.ruca4 i.year i.stateno || provnum:
	
	estimates store m1_ruca
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep  ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam ib4.ruca4 i.year i.stateno || provnum:
	
	estimates store m2_ruca
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep  ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam ib4.ruca4 i.year i.stateno || provnum:
		
	estimates store m3_ruca
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
estout m1_ruca m2_ruca m3_ruca using tables/bsgs2026jleo-table-SI07.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)

	
	/***************/
	/* Table SI.8. */
	/***************/

		/* Robustness: run with cases in which there is just one representative per chamber. */
	
menbreg def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if rep_house2== . & rep_senate2 == . || provnum:
	
	estimates store m1_onerep
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if rep_house2== . & rep_senate2 == . || provnum:
	
	estimates store m2_onerep
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if rep_house2== . & rep_senate2 == . || provnum:
	
	estimates store m3_onerep
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
estout m1_onerep m2_onerep m3_onerep using tables/bsgs2026jleo-table-SI08.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/***************/
	/* Table SI.9. */
	/***************/

		/* Robustness: exclude cases with multimember districts. */
	
menbreg def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno ///
	if !inlist(state, "AZ", "ID", "MD", "ND", "NH") & !inlist(state, "NJ", "SD", "VT", "WA", "WV") || provnum:
	
	estimates store m1_nommd
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno ///
	if !inlist(state, "AZ", "ID", "MD", "ND", "NH") & !inlist(state, "NJ", "SD", "VT", "WA", "WV") || provnum:
	
	estimates store m2_nommd
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno ///
	if !inlist(state, "AZ", "ID", "MD", "ND", "NH") & !inlist(state, "NJ", "SD", "VT", "WA", "WV") || provnum:
	
	estimates store m3_nommd
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
estout m1_nommd m2_nommd m3_nommd using tables/bsgs2026jleo-table-SI09.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.10. */
	/****************/

		/* Robustness: run with just high quality facility geo-merge results. */
		/* SLDU_nh_accur and SLDU_nh_accur have same accuracy, 0 is top category. */
	
menbreg def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if SLDL_nh_accur == 0 || provnum:
	
	estimates store m1_geohigh
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if SLDL_nh_accur == 0 || provnum:
	
	estimates store m2_geohigh
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj ///
	1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if SLDL_nh_accur == 0 || provnum:
	
	estimates store m3_geohigh
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)

estout m1_geohigh m2_geohigh m3_geohigh using tables/bsgs2026jleo-table-SI10.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.11. */
	/****************/

		/* Main models as Poisson with upper chamber district fixed effects. */

		/* Need to xtset at upper chamber level to run this. */
	
egen SLDU_id = group(state SLDU_sm)
	
xtset SLDU_id
	
xtpoisson def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)
	
	estimates store m1_fe_upp
	
xtpoisson def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)
	
	estimates store m2_fe_upp
	
xtpoisson def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)

	estimates store m3_fe_upp
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)

estout m1_fe_upp m2_fe_upp m3_fe_upp using tables/bsgs2026jleo-table-SI11.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant) ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.12. */
	/****************/

		/* Main models as Poisson with lower chamber district fixed effects. */

		/* Need to xtset at lower chamber level to run this. */
		
egen SLDL_id = group(state SLDL_sm)
	
xtset SLDL_id
	
xtpoisson def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)
	
	estimates store m1_fe_low
	
xtpoisson def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)
	
	estimates store m2_fe_low
	
xtpoisson def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)

	estimates store m3_fe_low
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
estout m1_fe_low m2_fe_low m3_fe_low using tables/bsgs2026jleo-table-SI12.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant) ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.13. */
	/****************/

		/* Main models as Poisson with facility fixed effects. */

xtpoisson def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)
	
	estimates store m1_fe_fac
	
xtpoisson def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)
	
	estimates store m2_fe_fac
	
xtpoisson def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe vce(robust)

	estimates store m3_fe_fac
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
estout m1_fe_fac m2_fe_fac m3_fe_fac using tables/bsgs2026jleo-table-SI13.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant) ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.14. */
	/****************/

		/* Main models as negative binomial with facility fixed effects - dispersion. */

		/* Need to xtset at nursing home level to run this. */

xtset provid

		/* May return error given number of FEs involved. */
		/* Hence -set maxvar 20000- in the header. */
		
xtnbreg def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe
	
	estimates store m1_nb_fe_fac
	
xtnbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe
	
	estimates store m2_nb_fe_fac
	
xtnbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year if surv_tot >= 2, fe

	estimates store m3_nb_fe_fac
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
estout m1_nb_fe_fac m2_nb_fe_fac m3_nb_fe_fac using tables/bsgs2026jleo-table-SI14.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant  lnalpha "Overdispersion (alpha)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/****************/
	/* Table SI.15. */
	/****************/

		/* Robustness: add clustering of SEs at state level. */

		/* Must remove four facilities with observations in more than one state. */
		
menbreg def_all loc_house_avg loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno ///
	if !inlist(provnum, "146038", "235594", "255250", "25A401") ///
	|| provnum: , vce(cluster stateno) 
	
	estimates store m1_clust_re
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno ///
	if !inlist(provnum, "146038", "235594", "255250", "25A401") ///
	|| provnum: , vce(cluster stateno) 
	
	estimates store m2_clust_re
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg ///
	1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno ///
	if !inlist(provnum, "146038", "235594", "255250", "25A401") ///
	|| provnum: , vce(cluster stateno) 
	
	estimates store m3_clust_re
	
		/* Effect of ideology for representatives with chamber majority status. */
	
lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
estout m1_clust_re m2_clust_re m3_clust_re using tables/bsgs2026jleo-table-SI15.txt, replace ///
	cells("b(star fmt(3)) se(par)") ///
	order(loc_house_avg loc_senate_avg hou_chamber govrep 1.loc_house_inmaj* 1.loc_senate_inmaj*) ///
	drop(*year *stateno) ///
	noomitted nobaselevels ///
	stats(N b_house_maj se_house_maj b_senate_maj se_senate_maj, fmt(%9.0gc %9.3f)) ///
	modelwidth(8) ///
	starlevels(* 0.05) legend ///
	transform(lnalpha exp(@) exp(@)) ///
	label varlabel(1.loc_house_inmaj "Lower Rep. In Majority" 1.loc_senate_inmaj "Lower Rep. In Majority" ///
	  1.loc_house_inmaj#c.loc_house_avg "Lower Rep. Ideology * In Majority" ///
	  1.loc_senate_inmaj#c.loc_senate_avg "Upper Rep. Ideology * In Majority" ///
	  _cons constant lnalpha "Overdispersion (alpha)" var(_cons[provnum]) "Var(u)") ///
	varwidth(35) ///
	eqlabels(none) ///
	collabels(none) ///
	mlabels(none)
	
	
	/*************************************************************************/
	/*************************************************************************/
	/* The following analyses are not reported in the paper or SI in detail, */
	/* but many are mentioned in the text and others are just additional     */
	/* checks or models that we ran that we include here for documentation.  */
	/*************************************************************************/
	/*************************************************************************/	
	
	/***********************************************************************************/
	/* Interpretation: run with local ideology measured as deviation from the chamber. */
	/* Note that doing so removes the chamber effect fully from the individual one.    */
	/***********************************************************************************/
	
		/* Local representation. */
		
menbreg def_all loc_house_avg_dist loc_senate_avg_dist ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
		/* Local and state representation. */
	
menbreg def_all loc_house_avg_dist loc_senate_avg_dist hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:

		/* Local and state representation with majority status interaction. */

menbreg def_all loc_house_avg_dist loc_senate_avg_dist hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg_dist ///
	1.loc_senate_inmaj#c.loc_senate_avg_dist ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
	/************************************************************/
	/* Robustness: exclude cases from 2002-2005 where we        */
	/*  forward-filled in the district from the 2000 districts. */
	/************************************************************/
	
	
menbreg def_all hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if backfill_SLDL==0 & backfill_SLDU==0 || provnum:
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if backfill_SLDL==0 & backfill_SLDU==0 || provnum:

menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj ///
	1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if backfill_SLDL==0 & backfill_SLDU==0 || provnum:
	

	/***************************************************************/
	/* Robustness: use a lower cutoff for bedsocc going over 100%. */
	/***************************************************************/

	
menbreg def_all loc_house_avg loc_senate_avg govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if bedsocc <= 1 || provnum:
		
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if bedsocc <= 1 || provnum:

menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj ///
	1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if bedsocc <= 1 || provnum:
	
	
	/*********************************************************************/
	/* Robustness: use upper chamber ideology on its own and with lower. */
	/*********************************************************************/

	
menbreg def_all sen_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno|| provnum:
		
menbreg def_all hou_chamber sen_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno|| provnum:
		
menbreg def_all loc_house_avg loc_senate_avg sen_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno|| provnum:
		
menbreg def_all loc_house_avg loc_senate_avg hou_chamber sen_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno|| provnum:
		
menbreg def_all loc_house_avg loc_senate_avg sen_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber sen_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
		
		/* Effect of ideology for representatives with chamber majority status. */
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					
	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	
	
	/************************************************************/
	/* Robustness: use majority party median for lower chamber. */
	/************************************************************/

	
menbreg def_all loc_house_avg loc_senate_avg govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year || provnum:
	
menbreg def_all loc_house_avg loc_senate_avg hou_majority govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno|| provnum:
	
menbreg def_all loc_house_avg loc_senate_avg hou_majority govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj ///
	1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year || provnum:
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)
	
	
	/**************************************************/
	/* Robustness: governor effect without state FEs. */
	/**************************************************/


menbreg def_all loc_house_avg loc_senate_avg govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year || provnum:
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year || provnum:
	
menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
	1.loc_house_inmaj 1.loc_senate_inmaj ///
	1.loc_house_inmaj#c.loc_house_avg 1.loc_senate_inmaj#c.loc_senate_avg ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year || provnum:
	
	lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					

	estadd scalar b_house_maj = r(estimate)
	estadd scalar se_house_maj = r(se)

	lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg		

	estadd scalar b_senate_maj = r(estimate)
	estadd scalar se_senate_maj = r(se)

	
	/******************************************************/
	/* Exploratory: look into governor's effect by party. */
	/******************************************************/


generat divRgov = govrep*(1 - unifiedD - unifiedR)
generat divDgov = govdem*(1 - unifiedD - unifiedR)
	
menbreg def_all loc_house_avg_dist loc_senate_avg_dist divRgov divDgov unifiedD ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
menbreg def_all loc_house_avg_dist loc_senate_avg_dist hou_chamber divRgov divDgov unifiedD ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
	
menbreg def_all loc_house_avg_dist loc_senate_avg_dist hou_chamber divRgov divDgov unifiedD ///
	1.loc_house_inmaj 1.loc_senate_inmaj 1.loc_house_inmaj#c.loc_house_avg_dist ///
	1.loc_senate_inmaj#c.loc_senate_avg_dist ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno || provnum:
		
		/* Effect of ideology for representatives with chamber majority status. */
	
lincom loc_house_avg + 1.loc_house_inmaj#c.loc_house_avg					
lincom loc_senate_avg + 1.loc_senate_inmaj#c.loc_senate_avg					
	
		/* Effect of chamber majority status by ideology. */
	
forvalues ideo = -3/3 {	
	
	lincom 1.loc_house_inmaj + 1.loc_house_inmaj#c.loc_house_avg*`ideo'					
	lincom 1.loc_senate_inmaj + 1.loc_senate_inmaj#c.loc_senate_avg*`ideo'					

	}
	

	/*******************************************************/
	/* Robustness: governor effect leave one out analysis. */
	/*******************************************************/

		/* Create an empty frame into which to post the results */

capture frame drop leaveoneout_gov 

frame create leaveoneout_gov str2(state) double(b_govrep se_govrep)
	
		/* Loop over the state to leave one out at at time. */
		/* Based on model 2 from Table 2. */
		
levelsof state, local(states)

foreach state of local states {

	display "Running model without `state'"

	quietly {

		menbreg def_all loc_house_avg loc_senate_avg hou_chamber govrep ///
			numbeds bedsocc rnhrspc med_caid med_care ///
			hospital own_nonp own_govt ib4.resfam i.year i.stateno if state!="`state'" || provnum:
		
		frame post leaveoneout_gov ("`state'") (_b[govrep]) (_se[govrep])
		
		}
	
	}
	
		/* Create a figure using the results in the leave one out frame. */
	
frame leaveoneout_gov {
	
	encode state, generat(stateno)
	
	generat ci_lo = b_govrep - 1.96*se_govrep
	generat ci_hi = b_govrep + 1.96*se_govrep
	
	twoway scatter stateno b_govrep, scheme(s1mono) ///
		mcolor(black) msize(small) ///
	 || rspike ci_lo ci_hi stateno, horizontal lwidth(medthin) lcolor(black) ///
		xlabel(#5, grid) ///
		ylabel(#49, valuelabel labsize(vsmall) angle(0) alternate) ///
		ytitle("") ///
		legend(off) ///
		ysize(5) xsize(4)
		
		graph export figures/bsgs2026jleo-analysis-govrep-leaveoneout.png, replace width(3000)
	
	}

	
	/*****************************************************/
	/* Exploratory: governor effect separately by state. */
	/*****************************************************/

		/* Keep all states - the variables won't be */
		/* included for those with no change in governor. */
		/* Run the regression to more quickly subset to relevant states. */
		/* Then leave out Alaska in 2002 since only one observation. */
		/* Based on model 2 from Table 2. */
	
regress def_all loc_house_avg_dist loc_senate_avg_dist hou_chamber 1.govrep#i.stateno ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno
	
menbreg def_all loc_house_avg_dist loc_senate_avg_dist hou_chamber 1.govrep#i.stateno ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year i.stateno if e(sample) & !(year == 2002 & stateno==2), ///
	iterate(15) || provnum:

		/* Plot the effect of govrep by state. */

coefplot, ///
	keep(1.govrep#*.stateno) baselevels horizontal ///
	ylabel(, labsize(vsmall)) ///
	xtitle("Estimated Coefficient on Rep. Gov") ytitle("State") ///
	xline(0, lpattern(solid) lcolor(red)) ///
	legend(off) 

	
	/**********************************************************************************/
	/* Exploratory: estimate the effect of local ideology by state with interactions. */
	/**********************************************************************************/

		/* Based on model 2 from Table 2. */
		
menbreg def_all c.loc_house_avg#ibn.stateno c.loc_senate_avg#ibn.stateno hou_chamber govrep ///
	numbeds bedsocc rnhrspc med_caid med_care ///
	hospital own_nonp own_govt ib4.resfam i.year ibn.stateno, nocons || provnum:

		/* Graph it - want better labels than coefplot will provide. */
		/* Create an empty frame into which to save and manipulate the results */

capture frame drop pooledstatelocal 

frame create pooledstatelocal

frame pooledstatelocal {
	
	parmest, norestore label omit 

	keep if strmatch(parm, "*loc_house_avg") | strmatch(parm, "*loc_senate_avg")
	
	drop if omit == 1
	
	generat stateno = real(substr(parm, 1, strpos(parm, ".") - 1))
	replace stateno = real(substr(parm, 1, strpos(parm, "b.") - 1)) if missing(stateno)
	generat chamber = "low" if strmatch(parm, "*loc_house_avg")
	replace chamber = "upp" if strmatch(parm, "*loc_senate_avg")
	
	keep estimate min95 max95 stateno chamber
	
	reshape wide estimate min95 max95, i(stateno) j(chamber) string
	
	}
	
		/* Connect the new frame to the base NH data set (the default frame). */
	
frlink m:1 stateno, frame(pooledstatelocal) generat(link_coefs) 

frget estimate* min95* max95*, from(link_coefs)

summarize estimate* if e(sample)

bysort stateno: replace min95upp = . if _n != 1
bysort stateno: replace min95low = . if _n != 1
bysort stateno: replace max95upp = . if _n != 1
bysort stateno: replace max95low = . if _n != 1
bysort stateno: replace estimateupp = . if _n != 1
bysort stateno: replace estimatelow = . if _n != 1

encode state, generat(temp) label(stateno)
label values stateno stateno
drop temp
	
twoway rspike min95low max95low stateno, horizontal ///
	lcolor(stc1) ///
 || scatter stateno estimatelow, ///
	mcolor(stc1) ///
	ylabel(1/50, nogrid valuelabel labsize(vsmall)) ///
	yscale(reverse) ///
	xtitle("Estimated Coefficient") ytitle("") ///
	title("Lower Chamber") ///
	xline(0, lpattern(solid) lcolor(red)) ///
	legend(off) ///
	xsize(4) ysize(6) ///
	name(lower, replace)
	
twoway rspike min95upp max95upp stateno, horizontal ///
	lcolor(stc1) ///
 || scatter stateno estimateupp, ///
	mcolor(stc1) ///
	ylabel(1/50, nogrid valuelabel labsize(vsmall)) ///
	yscale(reverse) ///
	xtitle("Estimated Coefficient") ytitle("") ///
	title("Upper Chamber") ///
	xline(0, lpattern(solid) lcolor(red)) ///
	legend(off) ///
	xsize(4) ysize(6) ///
	name(upper, replace)
	
	graph combine upper lower, rows(1) imargin(tiny)
		
	graph export figures/bsgs2026jleo-analysis-local-bystatepooled.png, replace width(3000)

levelsof estimateupp, local(upp)
levelsof estimatelow, local(low)
	
twoway scatter estimateupp estimatelow, ///
	mlabel(state) msymb(i) mlabpos(0) mlabsize(vsmall) ///
	xtitle("Lower Chamber") ytitle("Upper Chamber") ///
	ytick(`upp', tposition(inside)) ///
	xtick(`low', tposition(inside)) ///
	xline(0, lpattern(solid)) yline(0, lpattern(solid)) ///
	aspectratio(1) ///
	xsize(5) ysize(5) ///
	note("Inner ticks show the marginal distribution of the coefficient on that axis.", size(vsmall) span)

	graph export figures/bsgs2026jleo-analysis-local-bystatepooled-scatter.png, replace width(3000)

	
	/***************************************************************************/
	/* Exploratory: estimate the effect of local ideology one state at a time. */
	/***************************************************************************/

		/* Create an empty frame into which to post the results */

capture frame drop statebystate 

frame create statebystate str2(state) long(obs) double(b_upp se_upp b_low se_low)

		/* Loop over the state to leave one out at at time. */
		
preserve 

drop if state == "NE" | state == "VT"

levelsof state, local(states)

foreach state of local states {

	display "Running model for `state'"

	quietly {

		/* Leave out state-level variables since they sometimes don't change within states. */
		
		menbreg def_all loc_house_avg loc_senate_avg ///
			numbeds bedsocc rnhrspc med_caid med_care ///
			hospital own_nonp own_govt ib4.resfam i.year if state=="`state'" & year > 2002 || provnum: 
			
		/* Post the results to the created frame. */
		
		frame post statebystate ("`state'") (e(N)) (_b[loc_house_avg]) (_se[loc_house_avg]) ///
			(_b[loc_senate_avg]) (_se[loc_senate_avg]) 
			
		}
	
	}
	
restore
	
		/* Run commands in the created frame to interpret the results. */
	
frame statebystate {
	
	encode state, generat(stateno)
	
	generat ci_lo_upp = b_upp- 1.96*se_upp
	generat ci_hi_upp = b_upp + 1.96*se_upp
	
	generat ci_lo_low = b_low- 1.96*se_low
	generat ci_hi_low = b_low + 1.96*se_low
	
	sum b_upp [fw=obs]
	
	twoway scatter stateno b_upp, scheme(s1mono) ///
		mcolor(black) msize(small) ///
	 || rspike ci_lo_upp ci_hi_upp stateno, horizontal lwidth(medthin) lcolor(black) ///
		xlabel(#5, grid) ///
		ylabel(#49, valuelabel labsize(vsmall) angle(0) alternate) ///
		ytitle("") ///
		xline(0, lcolor(red)) ///
		xline(`=r(mean)', lcolor(gs10)) ///
		title(Upper Chamber) ///
		legend(off) ///
		ysize(5) xsize(4) ///
		name(upper, replace)
		
	sum b_upp [fw=obs]
	
	twoway scatter stateno b_low, scheme(s1mono) ///
		mcolor(black) msize(small) ///
	 || rspike ci_lo_low ci_hi_low stateno, horizontal lwidth(medthin) lcolor(black) ///
		xlabel(#5, grid) ///
		ylabel(#49, valuelabel labsize(vsmall) angle(0) alternate) ///
		ytitle("") ///
		xline(0, lcolor(red)) ///
		xline(`=r(mean)', lcolor(gs10)) ///
		title(Lower Chamber) ///
		legend(off) ///
		ysize(5) xsize(4) ///
		name(lower, replace)
		
	graph combine upper lower
		
	graph export figures/bsgs2026jleo-analysis-local-bystateseparate.png, replace width(3000)
	
	}

	
log close
clear
exit
